###########################################################################  
CXX=g++
CC=$(CXX)
PLATFORM=x86

ifeq ($(PLATFORM), x86)
    CXX=g++
else ifeq ($(PLATFORM), aarch64)
    CXX=/data/sdk/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu-g++
else ifeq ($(PLATFORM), v100)
    CXX=/opt/hisi-linux-nptl/arm-hisiv100-linux/target/bin/arm-hisiv100nptl-linux-g++
else ifeq ($(PLATFORM), x200)
    CXX=/opt/hisi-linux/x86-arm/arm-himix200-linux/bin/arm-himix200-linux-g++
else ifeq ($(PLATFORM), v300)
    CXX=/opt/hisi-linux/x86-arm/arm-hisiv300-linux/target/bin/arm-hisiv300-linux-g++
else ifeq ($(PLATFORM), v400)
    CXX=/opt/hisi-linux/x86-arm/arm-hisiv400-linux/target/bin/arm-hisiv400-linux-g++
else ifeq ($(PLATFORM), v500)
    CXX=/opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/arm-hisiv500-linux-g++
else ifeq ($(PLATFORM), v600)
    CXX=/opt/hisi-linux/x86-arm/arm-hisiv600-linux/target/bin/arm-hisiv600-linux-g++
else 
    echo "unknown platform!!!"
endif

###########################################################################  
LIST:= . ./thirdparty ../../output
SOURCE_LIST:= . ./thirdparty

OUTPUT_DIR:=../../output/$(PLATFORM)
TARGET_NAME:=testDemo
OBJECT:=$(OUTPUT_DIR)/$(TARGET_NAME)
SOURCES:=$(foreach list,$(SOURCE_LIST),$(wildcard $(list)/*.cpp))

VPATH:=$(foreach list,$(LIST),$(list))
#$(warning $(VPATH))
DELETE:=$(patsubst %.cpp,%.o,$(SOURCES))
DELETE+=$(patsubst %.cpp,%.d,$(SOURCES))
  
override CXXFLAGS+=-D__ENVIRONMENT_LINUX__
#override CXXFLAGS+=-DOS_IS_64BIT
override CXXFLAGS+=-DNDEBUG
#override CXXFLAGS+=-g
override CXXFLAGS+=$(patsubst %,-I%,$(subst ,,$(VPATH)))
override CFLAGS+=$(CXXFLAGS) -fpermissive
override LDFLAGS+=-rdynamic
override MAKEFLAGS += -s
########################################################################### 
$(OBJECT):$(patsubst %.cpp,%.o,$(SOURCES))  
	$(CXX) -o $@ $(CXXFLAGS) $(LDFLAGS) $^ -lGB28181Device -leXosip2 -losip2 -losipparser2 -lresolv -lrt -lpthread -L../../output/$(PLATFORM)
###########################################################################
%.d:%.cpp
	$(CXX) -MM $(CXXFLAGS) $(LDFLAGS) $< > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,\1.0 $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

-include $(SOURCES:.cpp=.d)
###########################################################################
.PHONY:clean
clean:
	rm $(DELETE) -f
	rm $(OBJECT) -f
